﻿using System;
using System.Collections.Generic;
using System.Text;
using SharpDiary.Core.Data;
using SharpDiary.Core.Utility;

namespace SharpDiary.Core.ORMapping
{
    /// <summary>
    /// 任务状态信息。
    /// </summary>
    [TableInfoAttribute("TaskStatusInfo")]
    public class TaskStatusInfo : DbMappingObjectBase
    {
        #region Fields & Properties

        private Int64 _id = -1;

        [FieldMapping(true, System.Data.DbType.Int64, true, true)]
        public Int64 Id
        {
            get { return _id; }
            set { _id = value; }
        }

        private string _name = string.Empty;

        [FieldMapping(false, System.Data.DbType.String, false, false)]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private Int64 _validStatus = 1;

        [FieldMapping(false, System.Data.DbType.String, false, false)]
        public Int64 ValidStatus
        {
            get { return _validStatus; }
            set { _validStatus = value; }
        }

        private byte[] _picture = new byte[0];

        [FieldMapping(false, System.Data.DbType.String, false, false)]
        public byte[] Picture
        {
            get { return _picture; }
            set { _picture = value; }
        }

        #endregion

        #region Constructors

        public TaskStatusInfo() { }

        #endregion

        #region Methods

        /// <summary>
        /// 获取所有任务状态信息。
        /// </summary>
        /// <returns>所有任务状态信息</returns>
        public static List<TaskStatusInfo> GetAllStatus()
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("SELECT * FROM TaskStatusInfo");
            sql.AppendLine("where ValidStatus = 1");

            DataAccessService das = Utils.GetDataAccessServiceInstance();
            return DbObjectMappingHelper.QueryObjectList<TaskStatusInfo>(sql.ToString());
        }

        /// <summary>
        /// 获取指定编号的任务状态信息。
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>任务状态信息</returns>
        public static TaskStatusInfo GetTaskStatusInfoById(Int64 id)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("SELECT * FROM TaskStatusInfo");
            sql.AppendLine("where id = @id");

            DataAccessService das = Utils.GetDataAccessServiceInstance();
            return DbObjectMappingHelper.Query<TaskStatusInfo>(sql.ToString(),
              das.CreateParameter("@id", System.Data.DbType.Int64, id));
        }

        public override string ToString()
        {
            return (_name != null ? _name : string.Empty);
        }

        #endregion
    }
}
